'use strict';

const Controller = require('egg').Controller;
const {ObjectId}= require("mongodb");
class SubjectController extends Controller {
  async index() {
    const {ctx} = this;
    var {id} = ctx.params;
    try{
        var db =  this.app.mongodb;
        var res = await db.collection("article").find({_id:ObjectId(id)}).toArray();
        // console.log(res)
        ctx.body = {
            status:200,
            res
        }
    }catch(err){
        this.app.logger.error(err);
        ctx.status = 400;
        ctx.body = {
            status:400,
            msg:"输入的id值参数不合法"
        }
    }
   
  }
}

module.exports = SubjectController;
